package lesson19.notepad;

import java.util.Scanner;

public class SecuredNotepad extends SimpleNotepad implements ISecuredNotepad {

	Scanner sc = new Scanner(System.in);

	String password;

	SecuredNotepad(String password, int numberOfPages) {
		super(numberOfPages);
		if (password != null && password != "") {
			this.password = password;
		} else
			System.out
					.println("Wrong password format! Please restart the app!");
	}

	@Override
	public void addText(String addedText, int page) {
		if (validatePass()) {
			super.addText(addedText, page);
		}
	}

	@Override
	public boolean validatePass() {
		System.out.println("Enter password: ");
		String pass = sc.nextLine();
		return pass.equals(this.password);
	}

	@Override
	public void overwriteText(String newText, int page) {
		if (validatePass()) {
			super.overwriteText(newText, page);
		}
	}

	@Override
	public void deleteText(Page selectedPage) {
		if (validatePass()) {
			super.deleteText(selectedPage);
		}
	}

	@Override
	public void printPages() {
		if (validatePass()) {
			super.printPages();
		}
	}

	@Override
	public Page getPage(int pageNumber) {
		if (validatePass()) {
			return super.getPage(pageNumber);
		} else {
			Page blank = new Page("Blank");
			return blank;
		}
	}
}